package com.example.zhangxin.comevedio.activity.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.example.zhangxin.comevedio.R;
import com.example.zhangxin.comevedio.activity.fragment.FragmentFactory;
import com.example.zhangxin.comevedio.activity.fragment.HomeFragment;
import com.example.zhangxin.comevedio.activity.view.HomeView;

public class HomeActivity extends BaseActivity implements BottomNavigationBar.OnTabSelectedListener {

    private ImageView menu_iv;
    private TextView menu_name;
    private TextView menu_id;
    private TextView menu_dec;
    private FrameLayout home_fl;
    private BottomNavigationBar home_bnb;
    private HomeView hv;
    private FragmentManager manager;
    private FragmentTransaction ft;
    private Fragment fragment;
    private FragmentTransaction ft1;

    @Override
    public int getLayout() {
        return R.layout.activity_home;
    }

    @Override
    public void findView() {
        menu_iv = (ImageView) findViewById(R.id.menu_iv);
        menu_name = (TextView) findViewById(R.id.menu_name);
        menu_id = (TextView) findViewById(R.id.menu_id);
        menu_dec = (TextView) findViewById(R.id.menu_dec);
        home_fl = (FrameLayout) findViewById(R.id.home_fl);
        home_bnb = (BottomNavigationBar) findViewById(R.id.home_bnb);
        hv = (HomeView) findViewById(R.id.hv);
        setHomeBNB();
    }

    private void setHomeBNB() {
        home_bnb.setMode(BottomNavigationBar.MODE_SHIFTING);
        home_bnb.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
        home_bnb.addItem(new BottomNavigationItem(R.mipmap.ic_home_white_24dp,"首页").setActiveColorResource(R.color.blue))
                .addItem(new BottomNavigationItem(R.mipmap.ic_music_note_white_24dp,"才艺").setActiveColorResource(R.color.orange))
                .addItem(new BottomNavigationItem(R.mipmap.ic_tv_white_24dp,"视频").setActiveColorResource(R.color.grey))
                .addItem(new BottomNavigationItem(R.mipmap.ic_videogame_asset_white_24dp,"互动").setActiveColorResource(R.color.teal))
                .addItem(new BottomNavigationItem(R.mipmap.ic_favorite_white_24dp,"最爱").setActiveColorResource(R.color.brown))
                .setFirstSelectedPosition(0)
                .initialise();
    }

    @Override
    public void setData() {
        manager = getSupportFragmentManager();
        ft = manager.beginTransaction();
        HomeFragment fragment = new HomeFragment();
        ft.add(R.id.home_fl,fragment);
        ft.commit();
    }

    @Override
    public void setListener() {
        home_bnb.setTabSelectedListener(this);
    }

    @Override
    public void onTabSelected(int position) {
        fragment = FragmentFactory.createFragment(position);
        FragmentManager manager = getSupportFragmentManager();
        ft1 = manager.beginTransaction();
        ft1.replace(R.id.home_fl, fragment);
        ft1.commit();

    }

    @Override
    public void onTabUnselected(int position) {
    }

    @Override
    public void onTabReselected(int position) {

    }
}
